﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceAgent.StudentService;
using System.ServiceModel;
using System.Collections.ObjectModel;

namespace ServiceAgent
{
    public class StudentServiceAgent : IDisposable
    {
        StudentServiceClient proxy;

        public StudentServiceAgent()
        {
            proxy = new StudentServiceClient(); 
        }

        #region CauLacBoThamGia
        public CauLacBoThamGiaDTO GetCauLacBoThamGiaByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                CauLacBoThamGiaDTO obj =
                    proxy.GetCauLacBoThamGiaByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<CauLacBoThamGiaDTO> GetCauLacBoThamGiaBySinhVienID(int SinhVienIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<CauLacBoThamGiaDTO> obj =
                    proxy.GetCauLacBoThamGiaBySinhVienID(SinhVienIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveCauLacBoThamGia(CauLacBoThamGiaDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveCauLacBoThamGia(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveCauLacBoThamGiaList(ObservableCollection<CauLacBoThamGiaDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveCauLacBoThamGiaList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveCauLacBoThamGia(CauLacBoThamGiaDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveCauLacBoThamGia(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveCauLacBoThamGia(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveCauLacBoThamGiaByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region HocBong
        public HocBongDTO GetHocBongByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                HocBongDTO obj =
                    proxy.GetHocBongByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<HocBongDTO> GetHocBongBySinhVienID(int SinhVienIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<HocBongDTO> obj =
                    proxy.GetHocBongBySinhVienID(SinhVienIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveHocBong(HocBongDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveHocBong(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveHocBongList(ObservableCollection<HocBongDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveHocBongList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveHocBong(HocBongDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveHocBong(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveHocBong(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveHocBongByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region KhenThuong
        public KhenThuongDTO GetKhenThuongByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                KhenThuongDTO obj =
                    proxy.GetKhenThuongByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<KhenThuongDTO> GetKhenThuongBySinhVienID(int SinhVienIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<KhenThuongDTO> obj =
                    proxy.GetKhenThuongBySinhVienID(SinhVienIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveKhenThuong(KhenThuongDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveKhenThuong(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveKhenThuongList(ObservableCollection<KhenThuongDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveKhenThuongList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveKhenThuong(KhenThuongDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveKhenThuong(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveKhenThuong(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveKhenThuongByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region KyLuat
        public KyLuatDTO GetKyLuatByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                KyLuatDTO obj =
                    proxy.GetKyLuatByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<KyLuatDTO> GetKyLuatBySinhVienID(int SinhVienIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<KyLuatDTO> obj =
                    proxy.GetKyLuatBySinhVienID(SinhVienIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveKyLuat(KyLuatDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveKyLuat(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveKyLuatList(ObservableCollection<KyLuatDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveKyLuatList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveKyLuat(KyLuatDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveKyLuat(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveKyLuat(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveKyLuatByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region HoatDongDoanTheThamGia Methods
        public HoatDongDoanTheThamGiaDTO GetHoatDongDoanTheThamGiaByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                HoatDongDoanTheThamGiaDTO obj =
                    proxy.GetHoatDongDoanTheThamGiaByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<HoatDongDoanTheThamGiaDTO> GetHoatDongDoanTheThamGiaBySinhVienID(int SinhVienIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<HoatDongDoanTheThamGiaDTO> obj =
                    proxy.GetHoatDongDoanTheThamGiaBySinhVienID(SinhVienIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveHoatDongDoanTheThamGia(HoatDongDoanTheThamGiaDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveHoatDongDoanTheThamGia(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveHoatDongDoanTheThamGiaList(ObservableCollection<HoatDongDoanTheThamGiaDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveHoatDongDoanTheThamGiaList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveHoatDongDoanTheThamGia(HoatDongDoanTheThamGiaDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveHoatDongDoanTheThamGia(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveHoatDongDoanTheThamGia(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveHoatDongDoanTheThamGiaByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region HoSoDaNop Methods
        public HoSoDaNopDTO GetHoSoDaNopByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                HoSoDaNopDTO obj =
                    proxy.GetHoSoDaNopByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<HoSoDaNopDTO> GetHoSoDaNopBySinhVienID(int SinhVienIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<HoSoDaNopDTO> obj =
                    proxy.GetHoSoDaNopBySinhVienID(SinhVienIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SetHoSoDaNopListForSinhVien(int SinhVienID, ObservableCollection<HoSoDaNopDTO> listDTO)
        {
            try
            {
                proxy.Open();
                proxy.SetHoSoDaNopListForSinhVien(SinhVienID, listDTO);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void UnsetHoSoDaNopListForSinhVien(int SinhVienID, ObservableCollection<HoSoDaNopDTO> listDTO)
        {
            try
            {
                proxy.Open();
                proxy.UnsetHoSoDaNopListForSinhVien(SinhVienID, listDTO);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region NghienCuuKhoaHoc
        public NghienCuuKhoaHocDTO GetNghienCuuKhoaHocByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                NghienCuuKhoaHocDTO obj =
                    proxy.GetNghienCuuKhoaHocByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<NghienCuuKhoaHocDTO> GetNghienCuuKhoaHocBySinhVienID(int SinhVienIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<NghienCuuKhoaHocDTO> obj =
                    proxy.GetNghienCuuKhoaHocBySinhVienID(SinhVienIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveNghienCuuKhoaHoc(NghienCuuKhoaHocDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveNghienCuuKhoaHoc(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveNghienCuuKhoaHocList(ObservableCollection<NghienCuuKhoaHocDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveNghienCuuKhoaHocList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveNghienCuuKhoaHoc(NghienCuuKhoaHocDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveNghienCuuKhoaHoc(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveNghienCuuKhoaHoc(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveNghienCuuKhoaHocByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region NhatKy
        public NhatKyDTO GetNhatKyByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                NhatKyDTO obj =
                    proxy.GetNhatKyByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<NhatKyDTO> GetNhatKyBySinhVienID(int SinhVienIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<NhatKyDTO> obj =
                    proxy.GetNhatKyBySinhVienID(SinhVienIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveNhatKy(NhatKyDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveNhatKy(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveNhatKyList(ObservableCollection<NhatKyDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveNhatKyList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveNhatKy(NhatKyDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveNhatKy(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveNhatKy(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveNhatKyByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region SinhVien
        public ObservableCollection<SinhVienBasicDTO> GetSinhVienList()
        {
            try
            {
                proxy.Open();
                ObservableCollection<SinhVienBasicDTO> list =
                    proxy.GetSinhVienList();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public SinhVienBasicDTO GetSinhVienByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                SinhVienBasicDTO obj =
                    proxy.GetSinhVienByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<SinhVienBasicDTO> SearchSinhVien(string Query)
        {
            try
            {
                proxy.Open();
                ObservableCollection<SinhVienBasicDTO> obj =
                    proxy.SearchSinhVien(Query);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<SinhVienBasicDTO> SearchSinhVienByDonVi(string Query,int DonViID)
        {
            try
            {
                proxy.Open();
                ObservableCollection<SinhVienBasicDTO> obj =
                    proxy.SearchSinhVienByDonVi(Query, DonViID);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<SinhVienBasicDTO> SearchSinhVienByLop(string Query,int LopID)
        {
            try
            {
                proxy.Open();
                ObservableCollection<SinhVienBasicDTO> obj =
                    proxy.SearchSinhVienByLop(Query, LopID);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<SinhVienBasicDTO> GetSinhVienByDonViID(int DonViIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<SinhVienBasicDTO> obj =
                    proxy.GetSinhVienByDonViID(DonViIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<SinhVienBasicDTO> GetSinhVienByLopID(int LopIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<SinhVienBasicDTO> obj =
                    proxy.GetSinhVienByLopID(LopIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<SinhVienBasicDTO> GetSinhVienByTenDonVi(string TenDonViFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<SinhVienBasicDTO> obj =
                    proxy.GetSinhVienByTenDonVi(TenDonViFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<SinhVienBasicDTO> GetSinhVienByTenLop(string TenLopFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<SinhVienBasicDTO> obj =
                    proxy.GetSinhVienByTenLop(TenLopFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public SinhVienDetailDTO GetSinhVienDetailByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                SinhVienDetailDTO obj =
                    proxy.GetSinhVienDetailByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public SinhVienDetailDTO GetSinhVienDetailByMa(string MaFilter)
        {
            try
            {
                proxy.Open();
                SinhVienDetailDTO obj =
                    proxy.GetSinhVienDetailByMa(MaFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public SinhVienDetailDTO GetSinhVienDetailByTen(string TenFilter)
        {
            try
            {
                proxy.Open();
                SinhVienDetailDTO obj =
                    proxy.GetSinhVienDetailByTen(TenFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveSinhVien(SinhVienDetailDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveSinhVien(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveSinhVien(SinhVienDetailDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveSinhVien(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveSinhVien(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveSinhVienByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region ThamGiaOlympic
        public ThamGiaOlympicDTO GetThamGiaOlympicByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                ThamGiaOlympicDTO obj =
                    proxy.GetThamGiaOlympicByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<ThamGiaOlympicDTO> GetThamGiaOlympicBySinhVienID(int SinhVienIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<ThamGiaOlympicDTO> obj =
                    proxy.GetThamGiaOlympicBySinhVienID(SinhVienIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveThamGiaOlympic(ThamGiaOlympicDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveThamGiaOlympic(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveThamGiaOlympicList(ObservableCollection<ThamGiaOlympicDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveThamGiaOlympicList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveThamGiaOlympic(ThamGiaOlympicDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveThamGiaOlympic(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveThamGiaOlympic(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveThamGiaOlympicByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region ThayDoiTrongQuaTrinhHoc Methods
        public ThayDoiTrongQuaTrinhHocDTO GetThayDoiTrongQuaTrinhHocByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                ThayDoiTrongQuaTrinhHocDTO obj =
                    proxy.GetThayDoiTrongQuaTrinhHocByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<ThayDoiTrongQuaTrinhHocDTO> GetThayDoiTrongQuaTrinhHocBySinhVienID(int SinhVienIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<ThayDoiTrongQuaTrinhHocDTO> obj =
                    proxy.GetThayDoiTrongQuaTrinhHocBySinhVienID(SinhVienIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveThayDoiTrongQuaTrinhHoc(ThayDoiTrongQuaTrinhHocDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveThayDoiTrongQuaTrinhHoc(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveThayDoiTrongQuaTrinhHocList(ObservableCollection<ThayDoiTrongQuaTrinhHocDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveThayDoiTrongQuaTrinhHocList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveThayDoiTrongQuaTrinhHoc(ThayDoiTrongQuaTrinhHocDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveThayDoiTrongQuaTrinhHoc(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveThayDoiTrongQuaTrinhHoc(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveThayDoiTrongQuaTrinhHocByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region VanBangDuocNhan
        public VanBangDuocNhanDTO GetVanBangDuocNhanByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                VanBangDuocNhanDTO obj =
                    proxy.GetVanBangDuocNhanByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<VanBangDuocNhanDTO> GetVanBangDuocNhanBySinhVienID(int SinhVienIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<VanBangDuocNhanDTO> obj =
                    proxy.GetVanBangDuocNhanBySinhVienID(SinhVienIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveVanBangDuocNhan(VanBangDuocNhanDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveVanBangDuocNhan(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveVanBangDuocNhanList(ObservableCollection<VanBangDuocNhanDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveVanBangDuocNhanList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveVanBangDuocNhan(VanBangDuocNhanDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveVanBangDuocNhan(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveVanBangDuocNhan(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveVanBangDuocNhanByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region Disposable
        public void Dispose()
        {
            this.DisposeExistingServiceClientIfRequired();
        }

        private void DisposeExistingServiceClientIfRequired()
        {
            if (proxy != null)
            {
                try
                {
                    if (proxy.State == CommunicationState.Faulted)
                    {
                        proxy.Abort();
                    }
                    else
                    {
                        proxy.Close();
                    }
                }
                catch
                {
                    proxy.Abort();
                }

                proxy = null;
            }
        }
        #endregion
    }
}
